using System;
using System.Collections.Generic;
using BanZuiCloudControlAgent.Core.Tasks.Enums;

namespace BanZuiCloudControlAgent.Core.Tasks.Utils
{
    /// <summary>
    /// 任务组辅助类，用于获取任务类型对应的任务组
    /// </summary>
    public static class TaskGroupHelper
    {
        /// <summary>
        /// 任务类型与任务组的映射关系
        /// </summary>
        private static readonly Dictionary<TaskType, TaskGroup> TaskTypeToGroupMap = new Dictionary<TaskType, TaskGroup>
        {
            // 交互类任务
            { TaskType.AddGroup, TaskGroup.Interactive },
            { TaskType.SendMessage, TaskGroup.Interactive },
            { TaskType.InviteFriend, TaskGroup.Interactive },
            { TaskType.ForwardMessage, TaskGroup.Interactive },
            
            // 系统类任务
            { TaskType.Update, TaskGroup.System },
            { TaskType.Config, TaskGroup.System },
            
            // 默认为Default组
            { TaskType.Unknown, TaskGroup.Default }
        };
        
        /// <summary>
        /// 获取任务类型对应的任务组
        /// </summary>
        /// <param name="taskType">任务类型</param>
        /// <returns>对应的任务组</returns>
        public static TaskGroup GetTaskGroup(TaskType taskType)
        {
            if (TaskTypeToGroupMap.TryGetValue(taskType, out TaskGroup group))
            {
                return group;
            }
            
            return TaskGroup.Default;
        }
        
        /// <summary>
        /// 判断任务是否属于指定的任务组
        /// </summary>
        /// <param name="taskType">任务类型</param>
        /// <param name="group">任务组</param>
        /// <returns>如果任务属于指定的任务组，则返回true；否则返回false</returns>
        public static bool IsTaskInGroup(TaskType taskType, TaskGroup group)
        {
            return GetTaskGroup(taskType) == group;
        }
    }
} 